<template>
  <div class="mod-purchaseproject__purchaseproject">
    <el-form :inline="true" :model="state.dataForm" @keyup.enter="state.getDataList()">
      <el-form-item>
        <el-input v-model="state.dataForm.purchaseProjectCode" placeholder="项目编号" clearable></el-input>
      </el-form-item>
      <el-form-item>
        <el-input v-model="state.dataForm.purchaseProjectName" placeholder="项目名称" clearable></el-input>
      </el-form-item>
      <el-form-item>
        <ren-select v-model="state.dataForm.purchaseProjectType" dict-type="purchase_project_type" placeholder="项目类型"></ren-select>
      </el-form-item>
      <el-form-item>
        <ren-select v-model="state.dataForm.processStatus" dict-type="purchase_process_status" placeholder="当前环节状态"></ren-select>
      </el-form-item>
      <el-form-item>
        <el-button @click="state.getDataList()">查询</el-button>
      </el-form-item>
      <el-form-item>
        <el-button v-if="state.hasPermission('purchaseproject:purchaseproject:save')" type="primary" @click="addOrUpdateHandle()">新增</el-button>
      </el-form-item>
<!--      <el-form-item>-->
<!--        <el-button v-if="state.hasPermission('purchaseproject:purchaseproject:delete')" type="danger" @click="state.deleteHandle()">删除</el-button>-->
<!--      </el-form-item>-->
<!--      <el-form-item>-->
<!--        <el-button v-if="state.hasPermission('purchaseproject:purchaseproject:export')" type="info" @click="state.exportHandle()">导出</el-button>-->
<!--      </el-form-item>-->
    </el-form>
    <el-table v-loading="state.dataListLoading" :data="state.dataList" border @selection-change="state.dataListSelectionChangeHandle" style="width: 100%">
      <el-table-column type="selection" header-align="center" align="center" width="50"></el-table-column>
              <el-table-column prop="purchaseProjectName" label="项目名称" header-align="center" align="center"></el-table-column>
              <el-table-column prop="purchaseProjectCode" label="项目编号" header-align="center" align="center"></el-table-column>
              <el-table-column prop="tradeCode" label="交易编号" header-align="center" align="center"></el-table-column>
              <el-table-column prop="purchaseProjectType" label="项目类型" header-align="center" align="center">
                <template v-slot="scope">
                  {{ state.getDictLabel("purchase_project_type", scope.row.purchaseProjectType) }}
                </template>
              </el-table-column>
<!--              <el-table-column prop="purchaseMode" label="采购方式" header-align="center" align="center">-->
<!--                <template v-slot="scope">-->
<!--                  {{ state.getDictLabel("purchase_mode", scope.row.purchaseMode) }}-->
<!--                </template>-->
<!--              </el-table-column>-->
<!--              <el-table-column prop="tenderOrganizeForm" label="采购组织形式" header-align="center" align="center">-->
<!--                <template v-slot="scope">-->
<!--                  {{ state.getDictLabel("tender_organize_form", scope.row.tenderOrganizeForm) }}-->
<!--                </template>-->
<!--              </el-table-column>-->
<!--              <el-table-column prop="purchaseShareId" label="采购人共享平台 ID，用于平台间数据交互" header-align="center" align="center"></el-table-column>-->
<!--              <el-table-column prop="purchaseBodyName" label="采购人名称" header-align="center" align="center"></el-table-column>-->
<!--              <el-table-column prop="agencyShareId" label="代理机构共享平台" header-align="center" align="center"></el-table-column>-->
<!--              <el-table-column prop="agencyBodyName" label="代理机构名称" header-align="center" align="center"></el-table-column>-->
<!--              <el-table-column prop="projectContent" label="采购内容与范围详细描述" header-align="center" align="center"></el-table-column>-->
<!--              <el-table-column prop="fundSource" label="项目资金来源" header-align="center" align="center"></el-table-column>-->
              <el-table-column prop="estimatesMoney" label="项目概算金额(元)" header-align="center" align="center"></el-table-column>
<!--              <el-table-column prop="linkMan" label="项目联系人" header-align="center" align="center"></el-table-column>-->
              <el-table-column prop="linkMobile" label="联系人手机号码" header-align="center" align="center"></el-table-column>
              <el-table-column prop="processStatus" label="当前环节状态" header-align="center" align="center">
                                <template v-slot="scope">
                                  {{ state.getDictLabel("purchase_process_status", scope.row.processStatus) }}
                                </template>
              </el-table-column>
<!--              <el-table-column prop="processName" label="当前环节名称" header-align="center" align="center"></el-table-column>-->
<!--              <el-table-column prop="createBodyShareId" label="创建主体共享平台 ID" header-align="center" align="center"></el-table-column>-->
<!--      公告是否发布，1 为是，0 为否-->
              <el-table-column prop="isPublishAnnouncement" label="公告是否发布" header-align="center" align="center">
                <template v-slot="scope">
                  {{ state.getDictLabel("is_or_no", scope.row.isPublishAnnouncement) }}
                </template>
              </el-table-column>
<!--              <el-table-column prop="createUser" label="项目创建人" header-align="center" align="center"></el-table-column>-->
<!--              <el-table-column prop="createTime" label="项目创建时间，格式：YYYY-MM-DD HH:MM:SS" header-align="center" align="center"></el-table-column>-->
<!--              <el-table-column prop="updateUser" label="最后更新人" header-align="center" align="center"></el-table-column>-->
<!--              <el-table-column prop="updateTime" label="最后更新时间，格式：YYYY-MM-DD HH:MM:SS" header-align="center" align="center"></el-table-column>-->
            <el-table-column label="操作" fixed="right" header-align="center" align="center" width="250">
        <template v-slot="scope">
          <el-button type="primary" link @click="showSectionList(scope.row)">标包配置</el-button>
          <el-button type="primary" link @click="showRuleList(scope.row)">开标规则</el-button>
          <el-button type="primary" link @click="planDetailHandle(scope.row.purchaseProjectId)">详情</el-button>
          <el-button v-if="state.hasPermission('purchaseproject:purchaseproject:update')" type="primary" link @click="addOrUpdateHandle(scope.row.purchaseProjectId)">修改</el-button>
          <el-button v-if="state.hasPermission('purchaseproject:purchaseproject:delete')" type="primary" link @click="state.deleteHandle(scope.row.purchaseProjectId)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination :current-page="state.page" :page-sizes="[10, 20, 50, 100]" :page-size="state.limit" :total="state.total" layout="total, sizes, prev, pager, next, jumper" @size-change="state.pageSizeChangeHandle" @current-change="state.pageCurrentChangeHandle"> </el-pagination>
    <!-- 弹窗, 新增 / 修改 -->
    <add-or-update ref="addOrUpdateRef" @refreshDataList="state.getDataList">确定</add-or-update>
    <plan-detail ref="planDetailRef" @refreshDataList="state.getDataList">确定</plan-detail>
    <!-- 字典类型数据 -->
    <el-drawer v-if="sectionDataVisible" v-model="sectionDataVisible" :title="state.purchaseProjectTitle" :size="900" :close-on-press-escape="false" class="rr-drawer"> <sectionList :purchaseProjectId="state.purchaseProjectId" :purchaseProjectCode="state.purchaseProjectCode"></sectionList></el-drawer>
    <el-drawer v-if="ruleDataVisible" v-model="ruleDataVisible" :title="state.purchaseProjectTitle" :size="900" :close-on-press-escape="false" class="rr-drawer"> <ruleList :purchaseProjectId="state.purchaseProjectId" :purchaseProjectCode="state.purchaseProjectCode"></ruleList></el-drawer>

  </div>
</template>

<script lang="ts" setup>
import useView from "@/hooks/useView";
import { reactive, ref, toRefs } from "vue";
import AddOrUpdate from "./purchaseproject-add-or-update.vue";
import PlanDetail from "./purchaseproject-detail.vue";

import sectionList from "../section/section.vue";
import ruleList from "../biddingrule/biddingrule.vue";

import { IObject } from "@/types/interface";
import { useRoute } from "vue-router";

const sectionDataVisible = ref(false);
const ruleDataVisible = ref(false);

const route = useRoute();

const view = reactive({
  deleteIsBatch: true,
  getDataListURL: "/purchaseproject/purchaseproject/page",
  getDataListIsPage: true,
  exportURL: "/purchaseproject/purchaseproject/export",
  deleteURL: "/purchaseproject/purchaseproject",
  dataForm: {
    purchaseProjectType: "",
    processStatus: ""
  },
  purchaseProjectId: "",
  purchaseProjectName: ""
});

const state = reactive({ ...useView(view), ...toRefs(view) });

const addOrUpdateRef = ref();
const addOrUpdateHandle = (id?: number) => {
  addOrUpdateRef.value.init(id);
};

const planDetailRef = ref();
const planDetailHandle = (id?: number) => {
  planDetailRef.value.init(id);
};

const showSectionList = (row: IObject) => {
  sectionDataVisible.value = true;
  state.purchaseProjectId = row.purchaseProjectId;
  state.purchaseProjectCode = row.purchaseProjectCode;
  state.purchaseProjectTitle = `${route.meta.title} - ${row.purchaseProjectName}`;
};

const showRuleList = (row: IObject) => {
  ruleDataVisible.value = true;
  state.purchaseProjectId = row.purchaseProjectId;
  state.purchaseProjectCode = row.purchaseProjectCode;
  state.purchaseProjectTitle = `${route.meta.title} - ${row.purchaseProjectName}`;
};

</script>
